//编写字符串中查找字符串，并且输出第一个字符所在位置的函数。
#include <stdio.h>
#include <string.h>
//function
char* pstion(char* s1, char* s2);

int main(void)
{
	char s1[19] = "found this";
	char s2[4] = "this";
	printf("%p\n", s1+9);
	printf("%p", pstion(s1, s2));
}

char* pstion(char* s1, char* s2)
{
	char* first = s1;
	char* mov1 = s1;
	char* mov2 = s2;
	int totall;
	totall = strlen(s1);
	int circul = 0;
	for (circul = 0; circul <= totall - 1; circul++)
	{
		if (*(mov1 + circul) = *s2)
			first = mov1 + circul;
	}
	return first;
}
//参考答案如下：
/* Programming Exercise 11-8 */
#include <stdio.h>
#define LEN 20
char * string_in(const char * s1, const char * s2);
int main(void)
{
 char orig[LEN] = "transportation";
 char * find;

 puts(orig);
 find = string_in(orig, "port");
 if (find)
 puts(find);
 else
 puts("Not found");
 find = string_in(orig, "part");
 if (find)
 puts(find);
 else
 puts("Not found");

 return 0;
}
#include <string.h>
char * string_in(const char * s1, const char * s2)
{
 int l2 = strlen(s2);
 int tries; /* maximum number of comparisons */
 int nomatch = 1; /* set to 0 if match is found */

 tries = strlen(s1) + 1 - l2;
 if (tries > 0)
 while (( nomatch = strncmp(s1, s2, l2)) && tries--)
 s1++;
 if (nomatch)
 return NULL;
 else
 return (char *) s1; /* cast const away */
}